local function DoAoe(inst, target, weapon)
    if target == nil or not target:IsValid() then
        return
    end
    local x, y, z = target.Transform:GetWorldPosition()

    inst.components.i26skill:EnBt(1)
    local dmgmult = inst.components.i26skill:GetMult()

    local radius = 3
    local AOE_RANGE_PADDING = 3
    local MUST_TAGS = { "_combat"}
    local CANT_TAGS = { "INLIMBO", "wall",  "DECOR", "invisible", "FX",
    "notarget", "noattack", "playerghost", "player", "companion", "moonstorm_static" }

    local fx = SpawnPrefab("i26bfx1")
    fx.Transform:SetPosition(x, y, z)
    fx.AnimState:SetScale(radius/2, radius/2)
    
    inst.components.combat.ignorehitrange = true
    for k,v in pairs(TheSim:FindEntities(x, y, z, radius + AOE_RANGE_PADDING, MUST_TAGS, CANT_TAGS)) do
        if v:IsValid() 
        and not v:IsInLimbo()
        and v.components.health ~= nil 
        and not v.components.health:IsDead()
        and v.components.combat ~= nil then
            if v == target then
                dmgmult = math.max(dmgmult - 1, 0)
            end
            local x2, y2, z2 = v.Transform:GetWorldPosition()
            local range = v:GetPhysicsRadius(0) + radius
            if distsq(x, z, x2, z2) <= range * range and 
            (v.components.follower == nil or v.components.follower.leader == nil or not v.components.follower.leader:HasTag("player")) then    
                inst.components.combat:DoAttack(v, weapon, nil, nil, dmgmult)
            end
        end
    end
    inst.components.combat.ignorehitrange = false
    inst.components.i26skill:CancelSuperAtk(weapon)
end

local oldfn = ACTIONS.ATTACK.fn
ACTIONS.ATTACK.fn = function(act, ...)
    local ort = oldfn(act, ...)
    if act.doer.sg ~= nil and act.doer:HasTag("i26") then
        local weapon = act.doer.components.combat:GetWeapon()
        if act.doer:HasTag("i26sppatk") and weapon ~= nil and not weapon:HasTag("i26_laotie") then
            DoAoe(act.doer, act.target, weapon)
        end
    end

    return ort
end